﻿#include <iostream>
#include <fstream>
#include <iomanip>
#include <boost/algorithm/string.hpp>
#include "GSL_MatrixCaculate.h"
#include "LineParCheck.h"
#include <BPAFilesIO.h>
#include <BaseCommon.h>
#include"MathFunction.h"
#include <sstream>

#ifdef _WIN32
#pragma comment(lib, "./gsl/libgsl-0.lib")
#pragma comment(lib, "./gsl/libgslcblas-0.lib")
#endif

using namespace JGG;

LineParCheck::LineParCheck(BPA::BPAFilesIO::DatParse* datParse, const char* database, int caseid)
{
    this->datParse = datParse;
    this->database = database;
    this->caseid = caseid;

    inst = new BPA::BPAFilesIO::GetDatFromDb(datParse, database, caseid);
}
LineParCheck::~LineParCheck()
{
	LineLittleSwitchList.clear();					//存储存在问题的小开关支路
	//LINEVector LineInfUncomplet;	    //存储线路参数信息不完整的线路
	LineProblemList.clear();						//存储线路参数存在问题的线路
	LineLengthUnrational.clear();				//存储线路长度不合理的线路
	LineListNewc.clear();							//存储历史库对比完之后新添加线路
	LineInformationComplet.clear();			//存储线路信息完整的线路
	LineLengthExist.clear();						//存储填写了线路长度的线路
	LineLengthUnExist.clear();					//存储没有填写线路长度的线路
	LineInfUncomplet.clear();				    //存储线路参数信息不完整的线路
    if (inst)
    {
        delete inst;
        inst = nullptr;
    }
}
void LineParCheck::LittleSwitchHandle()
{
	LINEVector LineLListc = inst->GetLineLList();
	int size = LineLListc.size();
	for (int i = 0; i < size; i++)
	{
		if (((LineLListc[i].Xpu == 0.0001) || ((LineLListc[i].Xpu >= 0.0001) && (LineLListc[i].Xpu <= 0.0004))|| 
			(LineLListc[i].Xpu == 999999)|| (LineLListc[i].Xpu < 0.0001)) && (LineLListc[i].Bpu == 999999 || LineLListc[i].Bpu == 0)) //找出电抗为0.0001或者电抗值在0.0001至0.0004之间或者电抗没有填写的线路，即判断为小开关支路
		{
			if ((LineLListc[i].Rpu > 0.0001 && LineLListc[i].Rpu != 999999) || (LineLListc[i].Xpu == 999999) || (LineLListc[i].Bpu > 0.0001 && LineLListc[i].Bpu != 999999))
			{
				LineLittleSwitchList.push_back(LineLListc[i]);
			}
		}
	}
	LineLListc.clear();
}
void LineParCheck::LineLengthCaculate1(double a[])
{
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni1 = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	FindLineInfComplet();
	double MVA_BASEC = inst->GetMVA_BASE();
	double RXrate;
	double MLineLengthByR = 0, MLineLengthByX = 0;// 临时存储所有根据线路电阻和电抗计算得到的长度值
	double LineReffect, LineXeffect;   //临时存储线路阻抗有名值
	int Insize;       //存储信息完整的线路条数
	int rateID = 0;
	int CountAdd = 0;    //累加计数器
	Insize = LineInformationComplet.size();
	
	gsl_vector *LineLengthByR = gsl_vector_alloc(Insize);
	gsl_vector *LineLengthByX = gsl_vector_alloc(Insize);
	gsl_vector *LineLengthByWrite = gsl_vector_alloc(Insize);  //已填写的线路长度
	gsl_matrix *XM = gsl_matrix_alloc(2, Insize);
	gsl_matrix *YM = gsl_matrix_alloc(Insize, 1);
	double LineInfCompletnum = LineInformationComplet.size();
	
	GSLMatrixCaculate GSLCaculate; //定义矩阵计算对象
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni1->GetRXstandardRatec();
	for (int i = 0; i < LineInfCompletnum; i++)
	{
		RXrate = 400 * (LineInformationComplet[i].Rpu / LineInformationComplet[i].Xpu);
		rateID = ReturnStandard(RXrate);
		//cout << rateID;
		if (rateID != 999)
		{
			LineReffect = LineInformationComplet[i].Rpu*LineInformationComplet[i].StartVol*LineInformationComplet[i].StartVol / MVA_BASEC;
			LineXeffect = LineInformationComplet[i].Xpu*LineInformationComplet[i].StartVol*LineInformationComplet[i].StartVol / MVA_BASEC;
			MLineLengthByR = LineReffect / RXstandardRatec[rateID].Rstandard;
			MLineLengthByX = LineXeffect / RXstandardRatec[rateID].Xstandard;
			gsl_vector_set(LineLengthByR, CountAdd, MLineLengthByR);
			gsl_vector_set(LineLengthByX, CountAdd, MLineLengthByX);
			gsl_vector_set(LineLengthByWrite, CountAdd, LineInformationComplet[i].linelength);
			//CountAdd++;
		}
		else
		{
			gsl_vector_set(LineLengthByR, CountAdd, LineInformationComplet[i].linelength);
			gsl_vector_set(LineLengthByX, CountAdd, LineInformationComplet[i].linelength);
			gsl_vector_set(LineLengthByWrite, CountAdd, LineInformationComplet[i].linelength);
			//CountAdd++;
		}
	}
	for (int i = 0; i < Insize; i++)
	{
		gsl_matrix_set(YM, i, 0, (gsl_vector_get(LineLengthByWrite, i) - GSLCaculate.GSL_Vector_Mean(LineLengthByWrite)));
		for (int j = 0; j < 2; j++)
		{
			if (j == 0)
			{
				gsl_matrix_set(XM, 0, i, (gsl_vector_get(LineLengthByR, i) - GSLCaculate.GSL_Vector_Mean(LineLengthByR)));
			}
			else
			{
				gsl_matrix_set(XM, 1, i, (gsl_vector_get(LineLengthByX, i) - GSLCaculate.GSL_Vector_Mean(LineLengthByX)));
			}
		}
	}
	gsl_matrix *A = gsl_matrix_alloc(XM->size1, XM->size1);
	gsl_matrix *D = gsl_matrix_alloc(XM->size1, YM->size2);
	gsl_matrix *tranXM = gsl_matrix_alloc(XM->size2, XM->size1);
	gsl_matrix *invA = gsl_matrix_alloc(A->size1, A->size2);
	gsl_matrix *B = gsl_matrix_alloc(A->size1, D->size2);
	gsl_matrix_transpose_memcpy(tranXM, XM);
	GSLCaculate.MatrixMultiply(XM, tranXM, A);
	GSLCaculate.MatrixMultiply(XM, YM, D);
	GSLCaculate.GetInverse(A, invA);
	GSLCaculate.MatrixMultiply(invA, D, B);
	double C = GSLCaculate.GSL_Vector_Mean(LineLengthByWrite) - gsl_matrix_get(B, 0, 0)*GSLCaculate.GSL_Vector_Mean(LineLengthByR) - gsl_matrix_get(B, (B->size1 - 1), (B->size2 - 1))*GSLCaculate.GSL_Vector_Mean(LineLengthByX);
	a[0] = gsl_matrix_get(B, 0, 0);
	a[1] = gsl_matrix_get(B, (B->size1 - 1), (B->size2 - 1));
	a[2] = C;
	//LineLengthRX = LineLengthpreR*gsl_matrix_get(B, 0, 0) + LineLengthpreX*gsl_matrix_get(B, (B->size1 - 1), (B->size2 - 1)) + C;
	gsl_matrix_free(XM);
	gsl_matrix_free(YM);
	gsl_matrix_free(A);
	gsl_matrix_free(B);
	gsl_matrix_free(D);
	gsl_matrix_free(tranXM);
	gsl_matrix_free(invA);
	gsl_vector_free(LineLengthByR);
	gsl_vector_free(LineLengthByX);
	gsl_vector_free(LineLengthByWrite);
	RXstandardRatec.clear();
	//return LineLengthRX;
}
int LineParCheck::ReturnStandard(double RXratec)
{
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni2 = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni2->GetRXstandardRatec();
	
	double ErrorTmp=0;
	int ErrorNum=0;
	int RXstandardRatecsize = RXstandardRatec.size();
	double *error = new double[RXstandardRatecsize];
	for (int j = 0; j<RXstandardRatecsize; j++)
	{
		error[j] = fabs(RXratec - RXstandardRatec[j].Rxrate);
	}
	for (int m = 0; m<RXstandardRatecsize; m++)
	{
		if (m == 0)
		{
			ErrorNum = 0;
			ErrorTmp = error[0];
		}
		else
		{
			if (error[m]<ErrorTmp)
			{
				ErrorTmp = error[m];
				ErrorNum = m;
			}
		}
	}
	delete[] error;
	if (RXratec > 400 || (RXratec<4 && RXratec>0))
	{
		return 999;
	}
	else
	{
		return ErrorNum;
	}
}
void LineParCheck::LineParameterJudgement(int IDnum, int RXrateIDnumc, double ParameterInterval1,
    double ParameterInterval2, double ParameterInterval3,double ParameterInterval4,
    double ParameterInterval5,double ParameterInterval6)
{
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni3 = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni3->GetRXstandardRatec();
    double MVA_BASEC = inst->GetMVA_BASE();
	
	double CaculateR, CaculateX, CaculateB; //定义变量存储通过标准阻抗导纳值计算得到的电阻电抗导纳值
	double ConverseR, ConverseX, ConverseB; //定义变量存储通过阻抗导纳标么值转换得到的阻抗导纳有名值 
	MathFunction MF;
	if (RXrateIDnumc == 999)
	{
		LineListNewc[IDnum].LinePro = "线路的参数可能存在问题，阻抗比不在标准阻抗比范围之内";
		LineListNewc[IDnum].Rpu_Process = 999999;
		LineListNewc[IDnum].Xpu_Process = 999999;
		LineListNewc[IDnum].Bpu_Process = 999999;
		LineListNewc[IDnum].linelength_Process = 999999;
		LineListNewc[IDnum].LineWrongPro = 1;
		//LineListCase1.push_back(LineListNewc[IDnum]);
		LineProblemList.push_back((LineListNewc[IDnum]));
	}
	else
	{
		LineListNewc[IDnum].RXrateID = RXrateIDnumc;
		LineTemp.push_back(LineListNewc[IDnum]);
		CaculateR = RXstandardRatec[RXrateIDnumc].Rstandard*LineListNewc[IDnum].linelength;
		CaculateX = RXstandardRatec[RXrateIDnumc].Xstandard*LineListNewc[IDnum].linelength;
		CaculateB = 0.000001*RXstandardRatec[RXrateIDnumc].Bstandard*LineListNewc[IDnum].linelength;
		ConverseR = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		ConverseX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		ConverseB = LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
		//计算线路可能错误的概率
		double LineXPer = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / (MVA_BASEC*LineListNewc[IDnum].linelength);
		double LineRPer = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / (MVA_BASEC*LineListNewc[IDnum].linelength);
		double LineBPer = 2 * LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol * LineListNewc[IDnum].linelength);
		double ux = (LineXPer - RXstandardRatec[RXrateIDnumc].Xstandard) ;
		double ur = (LineRPer - RXstandardRatec[RXrateIDnumc].Rstandard) ;
		double ub = (1000000 * LineBPer - RXstandardRatec[RXrateIDnumc].Bstandard) ;
		//cout << RXrateIDnumc << "基准值: " << MVA_BASEC << "电阻值: " << RXstandardRatec[RXrateIDnumc].Rstandard << "电抗值: " << RXstandardRatec[RXrateIDnumc].Xstandard
			//<< "电纳值: " << RXstandardRatec[RXrateIDnumc].Bstandard << "线路长度：" << LineListNewc[IDnum].linelength << endl;
		if( ux > 0)
		{
			LineListNewc[IDnum].LineXWrongPro = 2 * MF.phi(ux) -1;
			LineListNewc[IDnum].LineWrongPro = 2 * MF.phi(ux) - 1;
		}
		else
		{
			LineListNewc[IDnum].LineXWrongPro = 1 - 2 * MF.phi(ux);
			LineListNewc[IDnum].LineWrongPro = 1 - 2 * MF.phi(ux);
		}
		if( ur > 0)
		{
			LineListNewc[IDnum].LineRWrongPro = 2 * MF.phi(ur) -1;
			LineListNewc[IDnum].LineWrongPro = 2 * MF.phi(ur) - 1;
		}
		else
		{
			LineListNewc[IDnum].LineRWrongPro = 1 - 2 * MF.phi(ur);
			LineListNewc[IDnum].LineWrongPro = 1 - 2 * MF.phi(ur);
		}
		if( ub > 0)
		{
			LineListNewc[IDnum].LineBWrongPro = 2 * MF.phi(ub) -1;
			LineListNewc[IDnum].LineWrongPro = 2 * MF.phi(ub) - 1;
		}
		else
		{
			LineListNewc[IDnum].LineBWrongPro = 1 - 2 * MF.phi(ub);
			LineListNewc[IDnum].LineWrongPro = 1 - 2 * MF.phi(ub);
		}
		double fr = fabs(ConverseR / CaculateR);
		double fx = fabs(ConverseX / CaculateX);
		double fb = fabs(2*ConverseB / CaculateB);
		LineListNewc[IDnum].R_fr = fr;
		LineListNewc[IDnum].X_fx = fx;
		LineListNewc[IDnum].B_fb = fb;
		if (fr>ParameterInterval2 || fr<ParameterInterval1)
		{
			if (((fx <= ParameterInterval4) && (fx >= ParameterInterval3)) && (fb >= ParameterInterval5 && fb <= ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路的电阻参数可能存在问题";
				LineListNewc[IDnum].Rpu_Process = CaculateR*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Xpu_Process = 999999;
				LineListNewc[IDnum].Bpu_Process = 999999;
				LineListNewc[IDnum].linelength_Process = 999999;
				//LineListCase1.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back((LineListNewc[IDnum]));
			}
			else if ((fx > ParameterInterval4 || fx<ParameterInterval3) && (fb >= ParameterInterval5 && fb <= ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路的电阻、电抗参数可能存在问题";
				LineListNewc[IDnum].Rpu_Process = CaculateR*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Xpu_Process = CaculateX*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Bpu_Process = 999999;
				LineListNewc[IDnum].linelength_Process = 999999;
				//LineListCase1.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back((LineListNewc[IDnum]));
			}
			else if (((fx <= ParameterInterval4) && (fx >= ParameterInterval3)) && (fb < ParameterInterval5 || fb > ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路的电阻、电纳参数可能存在问题";
				LineListNewc[IDnum].Rpu_Process = CaculateR*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Xpu_Process = 999999;
				LineListNewc[IDnum].Bpu_Process = CaculateB*(LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol) / (2 * MVA_BASEC);
				LineListNewc[IDnum].linelength_Process = 999999;
				//LineListCase1.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back((LineListNewc[IDnum]));
			}
			else if ((fx>ParameterInterval4 || fx<ParameterInterval3) && (fb < ParameterInterval5 || fb > ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路的电阻、电抗、电纳参数可能存在问题";
				LineListNewc[IDnum].Rpu_Process = CaculateR*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Xpu_Process = CaculateX*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Bpu_Process = CaculateB*(LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol) / (2 * MVA_BASEC);
				LineListNewc[IDnum].linelength_Process = 999999;
				//LineListCase1.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back((LineListNewc[IDnum]));
			}
		}
		else if (fr <= ParameterInterval2 && fr >= ParameterInterval1)
		{
			if (((fx <= ParameterInterval4) && (fx >= ParameterInterval3)) && (fb >= ParameterInterval5 && fb <= ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路参数没问题";
				LineListNewc[IDnum].Rpu_Process = 999999;
				LineListNewc[IDnum].Xpu_Process = 999999;
				LineListNewc[IDnum].Bpu_Process = 999999;
				LineListNewc[IDnum].linelength_Process = 999999;
				LineNoProblemList.push_back(LineListNewc[IDnum]);
			}
			else if ((fx>ParameterInterval4 || fx<ParameterInterval3) && (fb >= ParameterInterval5 && fb <= ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路的电抗参数可能存在问题";
				LineListNewc[IDnum].Rpu_Process = 999999;
				LineListNewc[IDnum].Xpu_Process = CaculateX*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Bpu_Process = 999999;
				LineListNewc[IDnum].linelength_Process = 999999;
				//LineListCase1.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back((LineListNewc[IDnum]));
			}
			else if (((fx <= ParameterInterval4) && (fx >= ParameterInterval3)) && (fb < ParameterInterval5 || fb > ParameterInterval6))
			{
				if (LineListNewc[IDnum].Bpu != 999999)
				{
					LineListNewc[IDnum].LinePro = "线路的电纳参数可能存在问题";
					LineListNewc[IDnum].Rpu_Process = 999999;
					LineListNewc[IDnum].Xpu_Process = 999999;
					LineListNewc[IDnum].Bpu_Process = CaculateB*(LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol) / (2 * MVA_BASEC);
					LineListNewc[IDnum].linelength_Process = 999999;
					//LineListCase1.push_back(LineListNewc[IDnum]);
					LineProblemList.push_back((LineListNewc[IDnum]));
				}
			}
			else if ((fx>ParameterInterval4 || fx<ParameterInterval3) && (fb < ParameterInterval5 || fb > ParameterInterval6))
			{
				LineListNewc[IDnum].LinePro = "线路的电抗、电纳参数可能存在问题";
				LineListNewc[IDnum].Rpu_Process = 999999;
				LineListNewc[IDnum].Xpu_Process = CaculateX*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
				LineListNewc[IDnum].Bpu_Process = CaculateB*(LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol) / (2 * MVA_BASEC);
				LineListNewc[IDnum].linelength_Process = 999999;
				//LineListCase1.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back((LineListNewc[IDnum]));
			}
		}
	}
	RXstandardRatec.clear();
}
void LineParCheck::BadLineparameterCheck()
{
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	LineListNewc = inst->GetLineLList();
	int size1 = LineListNewc.size();
	//cout << "辨识线路参数数量：" << size1 << endl;
		int Case1Num = 0,
        Case2Num = 0,
        Case3Num = 0,
        Case4Num = 0,
        Case5Num = 0,
        Case6Num = 0,
        Case7Num = 0,
        Case8Num = 0,
        Case9Num = 0;
		for (int i = 0; i <size1; i++)	//
	{
		//cout << i << endl;
		//cout << LineListNewc[i].DatLineNum <<","<< LineListNewc[i].Xpu << "," << LineListNewc[i].Bpu 
		//	<< "," << LineListNewc[i].Rpu << "," << LineListNewc[i].linelength << endl;
		if ((LineListNewc[i].Xpu == 0.0001) || ((LineListNewc[i].Xpu >= 0.0001) && (LineListNewc[i].Xpu <= 0.0004)) ||
			(LineListNewc[i].Xpu == 999999) || (LineListNewc[i].Xpu < 0.0001)) //找出电抗为0.0001或者电抗值在0.0001至0.0004之间或者电抗没有填写的线路，即判断为小开关支路
		{
			LineLittleSwitchList.push_back(LineListNewc[i]);
		}
		else
		{
			if(LineListNewc[i].Xpu != 999999)
			{
				if(LineListNewc[i].Rpu != 999999)
				{
					if(LineListNewc[i].Bpu != 999999)
					{
						if((LineListNewc[i].linelength != 999999))
						{
							//线路参数完整
							LineListNewc[i].LineSort = 1;
							Case1Num = Case1Num + 1;
						}
						else
						{
							//线路长度不存在
							LineListNewc[i].LineSort = 2;
							Case2Num = Case2Num +1;
						}
					}
					else
					{
						if((LineListNewc[i].linelength != 999999))
						{
							//线路电纳不存在
							LineListNewc[i].LineSort = 3;
							Case3Num = Case3Num + 1;
						}
						else
						{
							//线路电纳、长度不存在
							LineListNewc[i].LineSort = 7;
							Case7Num = Case7Num + 1; 
						}
					}
				}
				else
				{
					if(LineListNewc[i].Bpu != 999999)
					{
						if((LineListNewc[i].linelength != 999999))
						{
							//线路电阻不存在
							LineListNewc[i].LineSort = 4;
							Case4Num = Case4Num + 1;
						}
						else
						{
							//线路电阻、长度不存在
							LineListNewc[i].LineSort = 6;
							Case6Num = Case6Num + 1;
						}
					}
					else
					{
						if((LineListNewc[i].linelength != 999999))
						{
							//线路电阻、电纳不存在
							LineListNewc[i].LineSort = 5;
							Case5Num = Case5Num +1;
						}
						else
						{
							//线路电纳、电阻、长度不存在
							LineListNewc[i].LineSort = 8;
							Case8Num = Case8Num +1;
						}
					}
				}
			}
			else
			{
				//线路电抗不存在
				LineListNewc[i].LineSort = 9;
				Case9Num = Case9Num +1;
			}
			switch(LineListNewc[i].LineSort)
			{
				case 1:
					{
						//cout << "线路参数完整" << endl;
						BadLineparameterCheckCase1(i);
						break;
					}
				case 2:
					{
						//cout << "线路长度不存在" << endl;
						BadLineparameterCheckCase2(i);
						break;
					}
				case 3:
					{
						//cout << "线路电纳不存在" << endl;
						BadLineparameterCheckCase3(i);
						break;
					}
				case 4:
					{
						//cout << "线路电阻不存在" << endl;
						BadLineparameterCheckCase4(i);
						break;
					}
				case 5:
					{
						//cout << "线路电阻、电纳不存在" << endl;
						BadLineparameterCheckCase5(i);
						break;
					}
				case 6:
					{
						//cout << "线路电阻、长度不存在" << endl;
						BadLineparameterCheckCase6(i);
						break;
					}
				case 7:
					{
						//cout << "线路电纳、长度不存在" << endl;
						BadLineparameterCheckCase7(i);
						break;
					}
				case 8:
					{
						//cout << "线路电纳、电阻、长度不存在" << endl;
						BadLineparameterCheckCase8(i);
						break;
					}
				case 9:
					{
						//cout << "线路电抗不存在" << endl;
						BadLineparameterCheckCase9(i);
						break;
					}
				default:
					{
						//cout<<"system failed"<<endl;
					}
			}
		}
	}
	LineCaseNumList[0] = Case1Num;
	LineCaseNumList[1] = Case2Num;
	LineCaseNumList[2] = Case3Num;
	LineCaseNumList[3] = Case4Num;
	LineCaseNumList[4] = Case5Num;
	LineCaseNumList[5] = Case6Num;
	LineCaseNumList[6] = Case7Num;
	LineCaseNumList[7] = Case8Num;
	LineCaseNumList[8] = Case9Num;
	cout<<"Case1Num： "<<Case1Num<<endl;
	cout<<"Case2Num： "<<Case2Num<<endl;
	cout<<"Case3Num： "<<Case3Num<<endl;
	cout<<"Case4Num： "<<Case4Num<<endl;
	cout<<"Case5Num： "<<Case5Num<<endl;
	cout<<"Case6Num： "<<Case6Num<<endl;
	cout<<"Case7Num： "<<Case7Num<<endl;
	cout<<"Case8Num： "<<Case8Num<<endl;
	cout<<"Case9Num： "<<Case9Num<<endl;
}
void LineParCheck::BadLineWriteToDat()
{
	string FileName = inst->GetFileName();
	FindLineLenghExist();
	int size = LineInfUncomplet.size();
	int sizec = LineProblemList.size();
	int sizecc = LineLittleSwitchList.size();
	std::ofstream FunctionResult((FileName + "-ProblemLine"+ ".dat").c_str(), ios::out);
	setiosflags(ios::right);
	FunctionResult << "普通交流线路参数可能存在问题线路列表：" << endl << endl;
	FunctionResult << "始端母线" << "  " << setw(8) << "始端电压" << "  " << setw(8) << "末端母线" << "  " << setw(8) << "末端电压" << "  " << setw(8) << "线路电阻值" << "  " << setw(8) << "线路电抗值" << "   " << setw(8) << "线路电纳值" << "   " << setw(8) << "线路长度"
		<< "      " << "线路问题" << endl;
	for (int i = 0; i < sizec; i++)
	{
		FunctionResult << LineProblemList[i].LineStart<< "  " << setw(8) << LineProblemList[i].StartVol << "  " << setw(8) <<LineProblemList[i].LineEnd << "  " << setw(8) << LineProblemList[i].EndVol << "  " << setw(8) << LineProblemList[i].Rpu << "     " << setw(8)
			<< LineProblemList[i].Xpu << "     " << setw(8) << LineProblemList[i].Bpu << "   " << setw(8) << LineProblemList[i].linelength <<
			"      " << LineProblemList[i].LinePro;
		FunctionResult << endl << endl;
	}
	FunctionResult << endl << "普通交流线路参数填写不全的线路列表：" << endl << endl;
	FunctionResult << "始端母线" << "  " << setw(8) << "始端电压" << "  " << setw(8) << "末端母线" << "  " << setw(8) << "末端电压" << "  " << setw(8) << "线路电阻" << "  " << setw(8)
		<< "线路电抗" << "  " << setw(8) << "线路电纳" << "      " << "线路问题" << endl;
	for (int i = 0; i < size; i++)
	{
		FunctionResult <<LineInfUncomplet[i].LineStart << "  " << setw(8) << LineInfUncomplet[i].StartVol << "  " << setw(8) << LineInfUncomplet[i].LineEnd<< "  " << setw(8) << LineInfUncomplet[i].EndVol << "  " << setw(8) << LineInfUncomplet[i].Rpu << "  " << setw(8)
			<< LineInfUncomplet[i].Xpu << "  " << setw(8) << LineInfUncomplet[i].Bpu << "      " << LineInfUncomplet[i].LinePro << endl << endl;
	}
	FunctionResult << endl << "线路参数可能存在问题的小开关支路：" << endl << endl;
	FunctionResult << "始端母线" << "  " << setw(8) << "始端电压" << "  " << setw(8) << "末端母线" << "  "
		<< setw(8) << "末端电压" << "  " << setw(8) << "线路电阻" << "  " << setw(8) << "线路电抗" << "  " << setw(8) << "线路电纳" << "      " << "线路问题" << endl;
	for (int i = 0; i < sizecc; i++)
	{
		FunctionResult << LineLittleSwitchList[i].LineStart << "  " << setw(8) << LineLittleSwitchList[i].StartVol << "  " << setw(8) << LineLittleSwitchList[i].LineEnd << "  "
			<< setw(8) << LineLittleSwitchList[i].EndVol << "  " << setw(8) << LineLittleSwitchList[i].Rpu << "  " << setw(8) << LineLittleSwitchList[i].Xpu << "  " << setw(8) << LineLittleSwitchList[i].Bpu << "      " << LineLittleSwitchList[i].LinePro << endl;
	}
	FunctionResult.close();
}

void LineParCheck::BadLineWriteToDatabase()
{
	int LineLittleSwitchNum, LinePromNum, UnRationalLengthNum,LineInfUncompletNum,LineNoPromNum;
	LineLittleSwitchNum = LineLittleSwitchList.size();   //小开关支路存在问题的数目
	LinePromNum = LineProblemList.size();				 //存在问题的非小开关支路的数目
	LineNoPromNum = LineNoProblemList.size();
	UnRationalLengthNum = LineLengthUnrational.size();
	LineInfUncompletNum = LineInfUncomplet.size();
	int LineListCase1Num,LineListCase2Num,LineListCase3Num,LineListCase4Num,LineListCase5Num,
		LineListCase6Num,LineListCase7Num,LineListCase8Num,LineListCase9Num;
	LineListCase1Num = LineListCase1.size();
	LineListCase2Num = LineListCase2.size();
	LineListCase3Num = LineListCase3.size();
	LineListCase4Num = LineListCase4.size();
	LineListCase5Num = LineListCase5.size();
	LineListCase6Num = LineListCase6.size();
	LineListCase7Num = LineListCase7.size();
	LineListCase8Num = LineListCase8.size();
	LineListCase9Num = LineListCase9.size();
	SqliteHelperDataBase db1;
	SqliteHelperBuffer bufSQL1;
	db1.open(database);
	char buf[600];
	std::memset(buf, 0, sizeof(buf));
	sprintf_s(buf, "delete from  LineLittleSwitchList where CaseID = (%d);", caseid);
	db1.execDML(buf);
	std::memset(buf, 0, sizeof(buf));
	sprintf_s(buf, "delete from  LineProblemList where CaseID = (%d);", caseid);
	db1.execDML(buf);
	std::memset(buf, 0, sizeof(buf));
	sprintf_s(buf, "delete from  LineNoProblemList where CaseID = (%d);", caseid);
	db1.execDML(buf);
	std::memset(buf, 0, sizeof(buf));
	sprintf_s(buf, "delete from  LineInfUncomplet where CaseID = (%d);", caseid);
	db1.execDML(buf);
	std::memset(buf, 0, sizeof(buf));
	sprintf_s(buf, "delete from  LineUnRationalLength where CaseID = (%d);", caseid);
	db1.execDML(buf);
	
	db1.execDML("begin transaction;");

	BUSVector BusListc = inst->GetBusList();

	/*****************************************************/

	for (int i = 0; i < LineInfUncompletNum; i++)
	{
		std::memset(buf, 0, sizeof(buf));
		boost::replace_all(LineInfUncomplet[i].LineStart, "'", "$");
		boost::replace_all(LineInfUncomplet[i].LineEnd, "'", "$");
		sprintf_s(buf, "insert into LineInfUncomplet(CaseID,LineID,StartBus,StartVol,EndBus,EndVol,ShuntFlag,LineR,LineX,LineB,LinePro,LineInfor) values (%d,%d,'%s',%f,'%s',%f,'%s',%f,%f,%f,'%s','%s');",
			caseid, LineInfUncomplet[i].LineID, LineInfUncomplet[i].LineStart.c_str(), LineInfUncomplet[i].StartVol, LineInfUncomplet[i].LineEnd.c_str(), LineInfUncomplet[i].EndVol, LineInfUncomplet[i].ShuntFlag.c_str(), LineInfUncomplet[i].Rpu, LineInfUncomplet[i].Xpu, LineInfUncomplet[i].Bpu, LineInfUncomplet[i].LinePro.c_str(), LineInfUncomplet[i].LineInfor.c_str());

		db1.execDML(buf);

	}
	for (int i = 0; i < LineLittleSwitchNum; i++)
	{
		std::memset(buf, 0, sizeof(buf));
		boost::replace_all(LineLittleSwitchList[i].LineStart, "'", "$");
		boost::replace_all(LineLittleSwitchList[i].LineEnd, "'", "$");
		sprintf_s(buf, "insert into LineLittleSwitchList (CaseID,LineID,StartBus,StartVol,EndBus,EndVol,LineR,LineX,LineB,Linelength,LineInfor) values (%d,%d,'%s',%f,'%s',%f,%f,%f,%f,%f,'%s');",
			caseid, i + 1, LineLittleSwitchList[i].LineStart.c_str(), LineLittleSwitchList[i].StartVol, LineLittleSwitchList[i].LineEnd.c_str(), LineLittleSwitchList[i].EndVol,
			LineLittleSwitchList[i].Rpu, LineLittleSwitchList[i].Xpu, LineLittleSwitchList[i].Bpu, LineLittleSwitchList[i].linelength, LineLittleSwitchList[i].LineInfor.c_str());
		db1.execDML(buf);
	}
	for (int i = 0; i < UnRationalLengthNum; i++)
	{
		std::memset(buf, 0, sizeof(buf));
		boost::replace_all(LineLengthUnrational[i].LineStart, "'", "$");
		boost::replace_all(LineLengthUnrational[i].LineEnd, "'", "$");
		sprintf_s(buf, "insert into LineUnRationalLength (CaseID,LineID,StartBus,StartVol,EndBus,EndVol,LineR,LineX,LineB,Linelength) values (%d,%d,'%s',%f,'%s',%f,%f,%f,%f,%f);",
			caseid, i + 1, LineLengthUnrational[i].LineStart.c_str(), LineLengthUnrational[i].StartVol, LineLengthUnrational[i].LineEnd.c_str(), LineLengthUnrational[i].EndVol,
			LineLengthUnrational[i].Rpu, LineLengthUnrational[i].Xpu, LineLengthUnrational[i].Bpu, LineLengthUnrational[i].linelength);
		db1.execDML(buf);
	}
	db1.execDML("commit transaction;");


	//try{
	//cout << LineProblemList.size() << endl;
	for (int i = 0; i < LinePromNum; i++)
	{
		//cout << caseid << LineProblemList[i].DatLineNum << "," << LineProblemList[i].LineID << "," << LineProblemList[i].LineStart
		//<< "," << LineProblemList[i].StartVol << "," << LineProblemList[i].LineEnd <<","<< LineProblemList[i].EndVol
		//<< "," << LineProblemList[i].Rpu << "," << LineProblemList[i].Rpu_Process << "," << LineProblemList[i].Xpu 
		//<< "," << LineProblemList[i].Xpu_Process << "," << LineProblemList[i].Bpu << "," << LineProblemList[i].Bpu_Process 
		//<< "," << LineProblemList[i].ShuntFlag << "," << LineProblemList[i].LineWrongPro << "," << LineProblemList[i].LinePro 
		//<< "," << LineProblemList[i].linelength << "," << LineProblemList[i].linelength_Process << ","<<LineProblemList[i].LineInfor << endl;
		char buf[1000];
		boost::replace_all(LineProblemList[i].LineStart, "'", "$");
		boost::replace_all(LineProblemList[i].LineEnd, "'", "$");
		sprintf_s(buf, "insert into LineProblemList (CaseID,DatLineNum,LineID,StartBus,StartVol,EndBus,EndVol,LineR,Rpu_Process,LineX,Xpu_Process,LineB,Bpu_Process,ShuntFlag,LineWrongPro,LinePro,Linelength,Linelength_Process,LineInfor) values (%d,%d,%d,'%s',%f,'%s',%f,%f,%f,%f,%f,%f,%f,'%s',%f,'%s',%f,%f,'%s');",
			caseid, LineProblemList[i].DatLineNum, LineProblemList[i].LineID, LineProblemList[i].LineStart.c_str(), LineProblemList[i].StartVol, LineProblemList[i].LineEnd.c_str(), LineProblemList[i].EndVol,
			LineProblemList[i].Rpu, LineProblemList[i].Rpu_Process, LineProblemList[i].Xpu, LineProblemList[i].Xpu_Process, LineProblemList[i].Bpu, LineProblemList[i].Bpu_Process, LineProblemList[i].ShuntFlag.c_str(), LineProblemList[i].LineWrongPro, LineProblemList[i].LinePro.c_str(), LineProblemList[i].linelength,
			LineProblemList[i].linelength_Process, LineProblemList[i].LineInfor.c_str());

		db1.execDML(buf);
	}

	//stringstream oss;
	//oss.str("");
	//oss << "insert into LineProblemList (CaseID, DatLineNum, LineID, StartBus, StartVol, EndBus, EndVol, "
	//	<< "LineR, Rpu_Process, LineX, Xpu_Process, LineB, Bpu_Process, ShuntFlag, LineWrongPro, LinePro, "
	//	<< "Linelength, Linelength_Process, LineInfor ) values ("
	//	<< caseid << ", " << LineProblemList[i].DatLineNum << ", " << LineProblemList[i].LineID << ", "
	//	<< LineProblemList[i].LineStart.c_str() << ", " << LineProblemList[i].StartVol << ", "
	//	<< LineProblemList[i].LineEnd.c_str() << ", " << LineProblemList[i].EndVol << ", "
	//	<< LineProblemList[i].Rpu << ", " << LineProblemList[i].Rpu_Process << ", "
	//	<< LineProblemList[i].Xpu << ", " << LineProblemList[i].Xpu_Process << ", "
	//	<< LineProblemList[i].Bpu << ", " << LineProblemList[i].Bpu_Process << ", "
	//	<< LineProblemList[i].ShuntFlag.c_str() << ", " << LineProblemList[i].LineWrongPro << ", "
	//	<< LineProblemList[i].LinePro.c_str() << ", " << LineProblemList[i].linelength << ", "
	//	<< LineProblemList[i].linelength_Process << ", " << LineProblemList[i].LineInfor.c_str() << ");";
	//db1.execDML(oss.str().c_str());


	//for (int i = 0; i < LineNoPromNum; i++)
	//{
	//	char buf[1000];
	//	boost::replace_all(LineNoProblemList[i].LineStart,"'","$");
	//	boost::replace_all(LineNoProblemList[i].LineEnd,"'","$");
	//	sprintf_s(buf, "insert into LineNoProblemList (CaseID,DatLineNum,LineID,LineSort,StartBus,StartVol,EndBus,EndVol,LineR,Rpu_Process,LineX,Xpu_Process,LineB,Bpu_Process,ShuntFlag,LinePro,RXrateID,LineXWrongPro,LineRWrongPro,LineBWrongPro,Linelength,Linelength_Process,LineLengthXB,LineLengthRateX,LineLengthRateR,R_fr,X_fx,B_fb,LineInfor) values (%d,%d,%d,%d,'%s',%f,'%s',%f,%f,%f,%f,%f,%f,%f,'%s','%s',%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,'%s');",
	//		caseid, LineNoProblemList[i].DatLineNum, LineNoProblemList[i].LineID, LineNoProblemList[i].LineSort, LineNoProblemList[i].LineStart.c_str(), LineNoProblemList[i].StartVol,LineNoProblemList[i].LineEnd.c_str(), LineNoProblemList[i].EndVol,
	//		LineNoProblemList[i].Rpu, LineNoProblemList[i].Rpu_Process, LineNoProblemList[i].Xpu, LineNoProblemList[i].Xpu_Process, LineNoProblemList[i].Bpu, LineNoProblemList[i].Bpu_Process, LineNoProblemList[i].ShuntFlag.c_str(), LineNoProblemList[i].LinePro.c_str(),  LineNoProblemList[i].RXrateID,LineNoProblemList[i].LineXWrongPro,LineNoProblemList[i].LineRWrongPro,LineNoProblemList[i].LineBWrongPro, LineNoProblemList[i].linelength, 
	//		LineNoProblemList[i].linelength_Process, LineNoProblemList[i].LineLengthXB, LineNoProblemList[i].LineLengthRateX, LineNoProblemList[i].LineLengthRateR, LineNoProblemList[i].R_fr, LineNoProblemList[i].X_fx, LineNoProblemList[i].B_fb, LineNoProblemList[i].LineInfor.c_str());
	////cout<<LineProblemList[i].DatLineNum<<LineProblemList[i].LineID<<endl;
	//	db1.execDML(buf);
	//}




	//}
	/*catch (SqliteHelperException e)
	{
	std::cout << e.errorCode() << ":" << e.errorMessage() << std::endl;
	}*/
	/*	char buf1[200];
		sprintf_s(buf1, "update LineLittleSwitchList set LineR=NULL where LineR=999999");
		db1.execDML(buf1);
		sprintf_s(buf1, "update LineLittleSwitchList set LineX=NULL where LineX=999999");
		db1.execDML(buf1);
		sprintf_s(buf1, "update LineLittleSwitchList set LineB=NULL where LineB=999999");
		db1.execDML(buf1);
		*/
	/*sprintf_s(buf1, "update LineLittleSwitchList set Linelength=NULL where Linelength=999999");
	db1.execDML(buf1);*/
	/*	sprintf_s(buf1, "update LineProblemList set LineR=NULL where LineR=999999");
		db1.execDML(buf1);
		sprintf_s(buf1, "update LineProblemList set LineX=NULL where LineX=999999");
		db1.execDML(buf1);
		sprintf_s(buf1, "update LineProblemList set LineB=NULL where LineB=999999");
		db1.execDML(buf1);*/
	/*sprintf_s(buf1, "update LineProblemList set Rpu_Process=NULL where Rpu_Process=999999");
	db1.execDML(buf1);
	sprintf_s(buf1, "update LineProblemList set Xpu_Process=NULL where Xpu_Process=999999");
	db1.execDML(buf1);
	sprintf_s(buf1, "update LineProblemList set Bpu_Process=NULL where Bpu_Process=999999");
	db1.execDML(buf1);*/
	/*sprintf_s(buf1, "update LineProblemList set Linelength=NULL where Linelength=999999");
	db1.execDML(buf1);*/
	//db1.execDML("commit transaction;");
	db1.close();
	BusListc.clear();
}


void LineParCheck::FindLineInfComplet()
{
	LINEVector LineLListc = inst->GetLineLList();

	int i, size;
	size = LineLListc.size();
	for (i = 0; i < size; i++)
	{
		if (((LineLListc[i].Rpu / LineLListc[i].Xpu) != 0) && (LineLListc[i].linelength != 999999)
			&& (LineLListc[i].Rpu != 999999) && (LineLListc[i].Xpu != 999999))
		{
			LineInformationComplet.push_back(LineLListc[i]);
		}
		if (LineLListc[i].Xpu == 999999)
		{
			LineLListc[i].LinePro = "交流线路的电抗值没有填写";
			LineLListc[i].Rpu_Process = 999999;
			LineLListc[i].Xpu_Process = 999999;
			LineLListc[i].Bpu_Process = 999999;
			LineProblemList.push_back(LineLListc[i]);
		}
		if ((LineLListc[i].Rpu / LineLListc[i].Xpu > 1)&&(LineLListc[i].Rpu != 999999))
		{
			LineLListc[i].LinePro = "交流线路的电阻值大于电抗值";
			LineProblemList.push_back(LineLListc[i]);
		}
	}
	LineLListc.clear();
}
void LineParCheck::FindLineLenghExist()
{
	LINEVector LineLListc = inst->GetLineLList();
	int size = LineLListc.size();
	for (int i = 0; i < size; i++)
	{
		if ((LineLListc[i].Rpu == 999999) && (LineLListc[i].Xpu != 999999) && (LineLListc[i].Bpu != 999999))
		{
			LineLListc[i].LinePro = "没有填写线路电阻值";
			LineInfUncomplet.push_back(LineLListc[i]);
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电阻值" << endl;
			//LineProCounts[0]++;
			//return 0;
		}
		if ((LineLListc[i].Rpu != 999999) && (LineLListc[i].Xpu == 999999) && (LineLListc[i].Bpu != 999999))
		{
			LineLListc[i].LinePro = "没有填写线路电抗值";
			LineInfUncomplet.push_back(LineLListc[i]);
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电抗值" << endl;
			//LineProCounts[1]++;
			//return 0;
		}
		if ((LineLListc[i].Rpu != 999999) && (LineLListc[i].Xpu != 999999) && (LineLListc[i].Bpu == 999999))
		{
			LineLListc[i].LinePro = "没有填写线路电纳值";
			LineInfUncomplet.push_back(LineLListc[i]);
			/*if ((LineLListc[i].linelength != 999999))
			{
				LineLListc[i].LinePro = "No Susceptance Value";
				LineInfUncomplet.push_back(LineLListc[i]);
				LineLengthExist.push_back(LineLListc[i]);
			}
			else if (LineLListc[i].linelength == 999999)
			{
				LineLListc[i].LinePro = "No Susceptance Value";
				LineInfUncomplet.push_back(LineLListc[i]);
				LineLengthUnExist.push_back(LineLListc[i]);
			}*/
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电纳值" << endl;
			//LineProCounts[2]++;
			//return 0;
		}
		if ((LineLListc[i].Rpu == 999999) && (LineLListc[i].Xpu == 999999) && (LineLListc[i].Bpu != 999999))
		{
			LineLListc[i].LinePro = "没有填写线路电阻和电抗值";
			LineInfUncomplet.push_back(LineLListc[i]);
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电阻和电抗值" << endl;
			//LineProCounts[3]++;
			//return 1;
		}
		if ((LineLListc[i].Rpu == 999999) && (LineLListc[i].Xpu != 999999) && (LineLListc[i].Bpu == 999999)&&(LineLListc[i].Xpu != 0.0001))
		{
			LineLListc[i].LinePro = "没有填写线路电阻和电纳值";
			LineInfUncomplet.push_back(LineLListc[i]);
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电阻和电纳值" << endl;
			//LineProCounts[4]++;
			//return 0;
		}
		if ((LineLListc[i].Rpu != 999999) && (LineLListc[i].Xpu == 999999) && (LineLListc[i].Bpu == 999999))
		{
			LineLListc[i].LinePro = "没有填写线路电抗和电纳值";
			LineInfUncomplet.push_back(LineLListc[i]);
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电抗和电纳值" << endl;
			//LineProCounts[5]++;
			//return 0;
		}
		if ((LineLListc[i].Rpu == 999999) && (LineLListc[i].Xpu == 999999) && (LineLListc[i].Bpu == 999999))
		{
			LineLListc[i].LinePro = "没有填写线路电阻、电抗和电纳值";
			LineInfUncomplet.push_back(LineLListc[i]);
			//cout << "warning：" << BusListc[LineLListc[num].StartNum - 1].BusName << "  " << LineLListc[num].StartVol << "  " << BusListc[LineLListc[num].EndNum - 1].BusName << "没有填写线路电阻、电抗和电纳值" << endl;
			//LineProCounts[6]++;
			//return 0;
		}
		if ((LineLListc[i].Rpu != 999999) && (LineLListc[i].Xpu != 999999) && (LineLListc[i].Bpu != 999999))
		{
			if (LineLListc[i].linelength != 999999)
			{
				LineLengthExist.push_back(LineLListc[i]);
			}
			else if (LineLListc[i].linelength == 999999)
			{
				LineLengthUnExist.push_back(LineLListc[i]);
			}
		}
	}
	LineLListc.clear();
}
double LineParCheck::GetLineLengthXB(double LineX, double LineB)
{
	double LineLength = (LineX*LineB*1000000)/(0.1445*7.58);
	LineLength = sqrt(LineLength);
	return LineLength;
}

void LineParCheck::BadLineparameterCheckCase1(int IDnum)
{
	double MVA_BASEC = inst->GetMVA_BASE();
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni->GetRXstandardRatec();
	std::vector <StdLengthCfg> LstandardLengthc = ReadIni->GetLstandardLengthc();

	int LineProblem =0;
	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();

	double LengthInterval = Parameterc[6];//线路长度的相对偏差
	double P1 = Parameterc[0];
	double P2 = Parameterc[1];
	double P3 = Parameterc[2];
	double P4 = Parameterc[3];
	double P5 = Parameterc[4];
	double P6 = Parameterc[5];
	int LineLengthStandardSize = LstandardLengthc.size();
	double *error = new double[LineLengthStandardSize];
	for (int j = 0; j<LineLengthStandardSize; j++)
	{
		error[j] = fabs(LineListNewc[IDnum].StartVol - LstandardLengthc[j].Voltage);
	}
	double ErrorTmp=0;
	int ErrorNum=0;
	for (int m = 0; m<LineLengthStandardSize; m++)
	{
		if (m == 0)
		{
			ErrorNum = 0;
			ErrorTmp = error[0];
		}
		else
		{
			if (error[m]<ErrorTmp)
			{
				ErrorTmp = error[m];
				ErrorNum = m;
			}
		}
	}
	delete []error;
	error = NULL;
	if (LineListNewc[IDnum].linelength < LstandardLengthc[ErrorNum].LineLengthDown)
	{
		LineListNewc[IDnum].LinePro = "线路长度可能不合理";
		LineLengthUnrational.push_back(LineListNewc[IDnum]);
		LineProblem = 1;
	}
	if (LineListNewc[IDnum].linelength>LstandardLengthc[ErrorNum].LineLengthUp)
	{
		LineListNewc[IDnum].LinePro = "线路长度可能不合理";
		LineLengthUnrational.push_back(LineListNewc[IDnum]);
		LineProblem = 1;
	}
	if (LineProblem != 1)
	{
		double RXrate = 400 * LineListNewc[IDnum].Rpu / LineListNewc[IDnum].Xpu;
		double LineR = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		double LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		double LineB = 2*LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
		int RXrateIDnum = ReturnStandard(RXrate);
		double LineLengthcaculate = GetLineLengthXB(LineX,LineB);
		double LineLengthpreR = LineR / RXstandardRatec[RXrateIDnum].Rstandard;
		double LineLengthpreX = LineX / RXstandardRatec[RXrateIDnum].Xstandard;
		LineListNewc[IDnum].LineLengthRateR = LineLengthpreR;
		LineListNewc[IDnum].LineLengthRateX = LineLengthpreX;
		LineListNewc[IDnum].LineLengthXB = LineLengthcaculate;
		LineListNewc[IDnum].Xpu_Process = 1;//标识线路长度合理，不进行线路长度校验，直接辨识电阻、电抗、电纳参数的线路

		RXrateIDnum = ReturnStandard(RXrate);
		LineParameterJudgement(IDnum, RXrateIDnum,P1,P2,P3,P4,P5,P6);
		LineProblem = 0;
	}
	else if (LineProblem == 1)  //粗扫线路长度存在问题
	{
		double LineLengthcaculate = 0;
		double RXrate = 400 * LineListNewc[IDnum].Rpu / LineListNewc[IDnum].Xpu;
		int RXrateIDnum = ReturnStandard(RXrate);
		if (RXrateIDnum != 999)
		{
			//阻抗比反推线路的长度LineLengthcaculate（)
			double LineR, LineX,LineB;
			LineR = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
			LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
			LineB = 2*LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
			LineLengthcaculate = GetLineLengthXB(LineX,LineB);
			double LineLengthpreR = LineR / RXstandardRatec[RXrateIDnum].Rstandard;
			double LineLengthpreX = LineX / RXstandardRatec[RXrateIDnum].Xstandard;
			LineListNewc[IDnum].LineLengthRateR = LineLengthpreR;
			LineListNewc[IDnum].LineLengthRateX = LineLengthpreX;
			LineListNewc[IDnum].LineLengthXB = LineLengthcaculate;
			if (fabs(LineLengthcaculate - LineListNewc[IDnum].linelength) / LineListNewc[IDnum].linelength > LengthInterval)
			{
				if(fabs((LineLengthpreX-LineListNewc[IDnum].linelength))/LineListNewc[IDnum].linelength > LengthInterval)
				{
					if(((fabs(LineLengthcaculate/LineListNewc[IDnum].linelength)>6 && fabs(LineLengthcaculate/LineListNewc[IDnum].linelength)<15)) || 
						((fabs(LineLengthpreX/LineListNewc[IDnum].linelength)>6 && fabs(LineLengthpreX/LineListNewc[IDnum].linelength)<15)))
							{
							LineListNewc[IDnum].LinePro = "线路长度不合理，BPA中线路长度未按标准填写，缺小数点";
							LineListNewc[IDnum].Rpu_Process = 999999;
							LineListNewc[IDnum].Bpu_Process = 999999;
							LineListNewc[IDnum].Xpu_Process = 999999;
							LineListNewc[IDnum].linelength_Process = LineListNewc[IDnum].linelength*10;
							LineListNewc[IDnum].LineWrongPro = 1;
							//LineListCase1.push_back(LineListNewc[IDnum]);
							LineProblemList.push_back(LineListNewc[IDnum]);
							}
					else
					{
					if(fabs((LineLengthcaculate-LineLengthpreX))/LineLengthpreX > LengthInterval)
					{
						if(fabs((LineLengthpreR-LineLengthpreX))/LineLengthpreX > LengthInterval)
						{
							LineListNewc[IDnum].Rpu_Process = 999999;
							LineListNewc[IDnum].Bpu_Process = 999999;
							LineListNewc[IDnum].Xpu_Process = 999999;
							LineListNewc[IDnum].linelength_Process = 999999;
							LineListNewc[IDnum].LineWrongPro = 1;
							LineListNewc[IDnum].LinePro = "线路长度不合理";//XB、X、R比较不合理
							//LineListCase1.push_back(LineListNewc[IDnum]);
							LineProblemList.push_back(LineListNewc[IDnum]);
						}
						else
						{
							LineListNewc[IDnum].Rpu_Process = 999999;
							LineListNewc[IDnum].Bpu_Process = 999999;
							LineListNewc[IDnum].Xpu_Process = 999999;
							LineListNewc[IDnum].linelength_Process = LineLengthpreX;
							LineListNewc[IDnum].LineWrongPro = 1;
							LineListNewc[IDnum].LinePro = "线路长度不合理";//X、R比较合理
							//LineListCase1.push_back(LineListNewc[IDnum]);
							LineProblemList.push_back(LineListNewc[IDnum]);
						}
					}
					
					else
					{
						LineListNewc[IDnum].Rpu_Process = 999999;
						LineListNewc[IDnum].Bpu_Process = 999999;
						LineListNewc[IDnum].Xpu_Process = 999999;
						LineListNewc[IDnum].linelength_Process = LineLengthcaculate;
						LineListNewc[IDnum].LineWrongPro = 1;
						LineListNewc[IDnum].LinePro = "线路长度不合理";//XB、X比较合理
						//LineListCase1.push_back(LineListNewc[IDnum]);
						LineProblemList.push_back(LineListNewc[IDnum]);
					}
				}
				}
				else
				{
					LineParameterJudgement(IDnum, RXrateIDnum,P1,P2,P3,P4,P5,P6);
				}
			}
			else
			{
				LineParameterJudgement(IDnum, RXrateIDnum,P1,P2,P3,P4,P5,P6);
			}
				
				//double LineLengthcaculate = LineLengthpreR*num[0] + LineLengthpreX*num[1] + num[2];
				/*
				
		}
				else
				{
					if(fabs((LineLengthpreR-LineLengthpreX))/LineLengthpreX < LengthInterval) 
					{
						LineListNewc[IDnum].LinePro = "可能错误1：线路长度XB反推不合理修正";
					}
				LineListNewc[IDnum].LinePro = "可能错误1：线路长度XB反推不合理修正";
				LineProblemList.push_back(LineListNewc[IDnum]);//
		
				}
			}
			else
			{
				LineParameterJudgement(IDnum, RXrateIDnum,P1,P2,P3,P4,DB_NAME);
	
			}
			*/
		}
		else if (RXrateIDnum == 999)
		{
			LineListNewc[IDnum].LinePro = "线路的参数可能存在问题，阻抗比不在标准阻抗比范围之内";
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Bpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase1.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
		
			//continue;           
			Parameterc.clear();
			RXstandardRatec.clear();
			LstandardLengthc.clear();
		}
	}
}		

void LineParCheck::BadLineparameterCheckCase2(int IDnum)
{
	double MVA_BASEC = inst->GetMVA_BASE();
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni->GetRXstandardRatec();
	std::vector <StdLengthCfg> LstandardLengthc = ReadIni->GetLstandardLengthc();

	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();
	double LengthInterval = Parameterc[6];//线路长度的相对偏差
	double P1 = Parameterc[0];
	double P2 = Parameterc[1];
	double P3 = Parameterc[2];
	double P4 = Parameterc[3];
	double P5 = Parameterc[4];
	double P6 = Parameterc[5];
	/***********************************************************************/
	int ReturnIDnum = 0;
	double RXrate;
	RXrate = 400 * LineListNewc[IDnum].Rpu / LineListNewc[IDnum].Xpu;
	ReturnIDnum = ReturnStandard(RXrate);
	if (ReturnIDnum == 999)
	{
		LineListNewc[IDnum].LinePro = "线路的参数可能存在问题，阻抗比不在标准阻抗比范围之内";
		LineListNewc[IDnum].Rpu_Process = 999999;
		LineListNewc[IDnum].Xpu_Process = 999999;
		LineListNewc[IDnum].Bpu_Process = 999999;
		LineListNewc[IDnum].linelength_Process = 999999;
		LineListNewc[IDnum].LineWrongPro = 1;
		//LineListCase2.push_back(LineListNewc[IDnum]);
		LineProblemList.push_back(LineListNewc[IDnum]);
	}
	else
	{
		double LineR, LineX,LineB;
		LineR = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		LineB = 2*LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
		RXrate = 400 * LineR / LineX;
		double LineLengthXB = GetLineLengthXB(LineX,LineB);
		double LineLengthpreR = LineR / RXstandardRatec[ReturnIDnum].Rstandard;
		double LineLengthpreX = LineX / RXstandardRatec[ReturnIDnum].Xstandard;
		LineListNewc[IDnum].LineLengthXB = LineLengthXB;
		LineListNewc[IDnum].LineLengthRateX = LineLengthpreX;
		LineListNewc[IDnum].LineLengthRateR = LineLengthpreR;
		//cout<<"计算前"<<num[0]<<" "<<num[1]<<" "<<num[2]<<endl;
		//LineLengthCaculate1(num,DB_NAME);
		//cout<<"计算后"<<num[0]<<" "<<num[1]<<" "<<num[2]<<endl;
		//double LineLengthcaculate = LineLengthpreR*num[0] + LineLengthpreX*num[1] + num[2];
		if(fabs((LineLengthXB-LineLengthpreX))/LineLengthpreX > LengthInterval)
		{
			if(fabs((LineLengthpreR-LineLengthpreX))/LineLengthpreX > LengthInterval)
			{
			LineListNewc[IDnum].LinePro = "线路长度不合理";//XB、阻抗比反推对比线路长度不合理
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Bpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase2.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
			}
			else
			{
				LineListNewc[IDnum].LinePro = "线路长度不合理";//阻抗比反推对比线路长度合理
				LineListNewc[IDnum].Rpu_Process = 999999;
				LineListNewc[IDnum].Xpu_Process = 999999;
				LineListNewc[IDnum].Bpu_Process = 999999;
				LineListNewc[IDnum].linelength_Process = LineLengthpreX;
				LineListNewc[IDnum].LineWrongPro = 1;
				//LineListCase2.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back(LineListNewc[IDnum]);
			}
		}
		else
		{
			LineListNewc[IDnum].linelength = LineLengthXB;
			//LineListNewc[IDnum].linelength_Process = LineLengthXB;
			//cout<<LineListNewc[IDnum].linelength<<endl;
			int RXrateIDnum = 0;  //存储返回的配置文件所属ID
			//double CaculateR, CaculateX, CaculateB; //定义变量存储通过标准阻抗导纳值计算得到的电阻电抗导纳值
			//double ConverseR, ConverseX, ConverseB; //定义变量存储通过阻抗导纳标么值转换得到的阻抗导纳有名值 
			RXrateIDnum = ReturnStandard(RXrate);
			LineParameterJudgement(IDnum, RXrateIDnum,P1,P2,P3,P4,P5,P6);
			//LineLengthpreR = LineR / RXstandardRatec[ReturnIDnum].Rstandard;
			//LineLengthpreX = LineX / RXstandardRatec[ReturnIDnum].Xstandard;
			//LineLengthcaculate = LineLengthpreR*num[0] + LineLengthpreX*num[1] + num[2];
			//LineLengthUnExist[i].linelength = LineLengthcaculate;  //自动补足线路的长度	
		}
	}
	Parameterc.clear();
	RXstandardRatec.clear();
	LstandardLengthc.clear();
}

void LineParCheck::BadLineparameterCheckCase3(int IDnum)
{
	double MVA_BASEC = inst->GetMVA_BASE();
    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();
	double LengthInterval = Parameterc[6];//线路长度的相对偏差
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni->GetRXstandardRatec();
	double RXrate = 0;
	RXrate = 400 * LineListNewc[IDnum].Rpu / LineListNewc[IDnum].Xpu;
	int RXrateIDnum = 0;
	RXrateIDnum = ReturnStandard(RXrate);
	if (RXrateIDnum == 999)
	{
			LineListNewc[IDnum].LinePro = "线路的参数可能存在问题，阻抗比不在标准阻抗比范围之内";
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Bpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase3.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
	}
	else
	{
		double LineR, LineX, LineLengthR, LineLengthX;
		LineR = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		LineLengthR = LineR / RXstandardRatec[RXrateIDnum].Rstandard;
		LineLengthX = LineX / RXstandardRatec[RXrateIDnum].Xstandard;
		LineListNewc[IDnum].LineLengthRateX = LineLengthX;
		LineListNewc[IDnum].LineLengthRateR = LineLengthR;
		if ((fabs(LineLengthR - LineListNewc[IDnum].linelength) / LineListNewc[IDnum].linelength > LengthInterval) && (fabs(LineLengthX - LineListNewc[IDnum].linelength) / LineListNewc[IDnum].linelength > LengthInterval))
		{
			if (fabs(LineLengthR - LineLengthX) / LineLengthX < LengthInterval)
			{
				LineListNewc[IDnum].LinePro = "线路长度不合理,补齐电纳参数";//错误修正3：阻抗比X、R分别反推对比合理
				double LineLengthRX = (LineLengthR + LineLengthX) / 2;
				LineListNewc[IDnum].linelength_Process = LineLengthRX;        
				LineListNewc[IDnum].Bpu_Process = RXstandardRatec[RXrateIDnum].Bstandard * LineLengthRX;		// 补全电纳值
				LineListNewc[IDnum].Rpu_Process = 999999;
				LineListNewc[IDnum].Xpu_Process = 999999;
				LineListNewc[IDnum].LineWrongPro = 1;
				//LineListCase3.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back(LineListNewc[IDnum]);
			}
			else
			{
				LineListNewc[IDnum].LinePro = "线路长度不合理";//可能错误3：线路长度、阻抗比X、R分别反推对比不合理
				LineListNewc[IDnum].Rpu_Process = 999999;
				LineListNewc[IDnum].Xpu_Process = 999999;
				LineListNewc[IDnum].Bpu_Process = 999999;
				LineListNewc[IDnum].linelength_Process = 999999;
				LineListNewc[IDnum].LineWrongPro = 1;
				//LineListCase3.push_back(LineListNewc[IDnum]);
				LineProblemList.push_back(LineListNewc[IDnum]);
			}
		}
		else
		{
			double LineB = 0.000001*RXstandardRatec[RXrateIDnum].Bstandard * LineListNewc[IDnum].linelength;
			LineListNewc[IDnum].LinePro = "补齐电纳参数";
			LineListNewc[IDnum].Bpu_Process = LineB*(LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol) / (2 * MVA_BASEC);// 补全电纳值
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			LineProblemList.push_back(LineListNewc[IDnum]);
			//LineListNewc[IDnum].Bpu_Process = RXstandardRatec[RXrateIDnum].Bstandard * LineListNewc[IDnum].linelength;
			//LineListNewc[IDnum].ShuntFlag  = 7;//标识电纳不存在线路，根据阻抗比给出电纳推荐值，然后进行电阻、电抗、电纳辨识
			/*********************************************************************************************************************/
			//LineParameterJudgement(IDnum, RXrateIDnum, P1, P2, P3, P4, P5, P6, DB_NAME);//需要修改，是否需要再进行校验	

		}
	}
	Parameterc.clear();
	RXstandardRatec.clear();
}

void LineParCheck::BadLineparameterCheckCase4(int IDnum)
{
    double MVA_BASEC = inst->GetMVA_BASE();

    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();
	double LengthInterval = Parameterc[6];//线路长度的相对偏差

	double LineX, LineB;
	LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
	LineB = 2 * LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
	double LineLengthXB = GetLineLengthXB(LineX, LineB);
	LineListNewc[IDnum].LineLengthXB = LineLengthXB;
	if (fabs(LineLengthXB - LineListNewc[IDnum].linelength) / LineListNewc[IDnum].linelength < LengthInterval)
	{
		double AverageR = 0.083;//R用标准参数库均值给出推荐值,补全数据
		LineListNewc[IDnum].Rpu_Process = AverageR *LineListNewc[IDnum].linelength;
		LineListNewc[IDnum].LinePro = "补全电阻参数";//错误修正4：线路电阻不存在、XB反推长度对比合理
		LineListNewc[IDnum].Bpu_Process = 999999;
		LineListNewc[IDnum].Xpu_Process = 999999;
		LineListNewc[IDnum].linelength_Process = 999999;
		LineListNewc[IDnum].LineWrongPro = 1;
		//LineListCase4.push_back(LineListNewc[IDnum]);
		LineProblemList.push_back(LineListNewc[IDnum]);
	}
	else
	{
		//单值校验电抗，确定线路长度是否合理
		double AverageX = 0.32;			//根据标准参数库给出单位长度平均线路电抗参数值
		double LineLengthX = LineX / AverageX;
		LineListNewc[IDnum].LineLengthRateX = LineLengthX;
		if (fabs(LineLengthX - LineListNewc[IDnum].linelength) / LineListNewc[IDnum].linelength < LengthInterval)
		{
			//电阻通过标准值给出
			double AverageR = 0.083, AverageB = 3.64;//R用标准参数库均值给出推荐值,补全数据,均值如何确定
			LineListNewc[IDnum].Rpu_Process = AverageR *LineListNewc[IDnum].linelength;
			LineListNewc[IDnum].Bpu_Process = AverageB *LineListNewc[IDnum].linelength;
			LineListNewc[IDnum].LinePro = "补全电阻参数";//错误修正4：线路电阻不存在、X平均值反推对比合理
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase4.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
		}
		else
		{
			LineListNewc[IDnum].LinePro = "线路长度不合理";   //可能错误4：线路电阻不存在、辨识成功，无法修正，界面展示
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Bpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase4.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
			Parameterc.clear();
		}
	}	
	
}

void LineParCheck::BadLineparameterCheckCase5(int IDnum)
{
	double MVA_BASEC = inst->GetMVA_BASE();

    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();
	double LengthInterval = Parameterc[6];//线路长度的相对偏差

	double LineX;
	LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
	double AverageX = 0.32;			//给出单位长度平均线路电抗参数值
	double LineLengthX = LineX / AverageX;
	LineListNewc[IDnum].LineLengthRateX = LineLengthX;
	if (fabs(LineLengthX - LineListNewc[IDnum].linelength) / LineListNewc[IDnum].linelength < LengthInterval)
	{
		//线路长度合理				
		//电阻、电纳通过均值给出
		double AverageR = 0.083, AverageB = 3.64;//R、B用标准参数库均值给出推荐值,补全数据
		LineListNewc[IDnum].Rpu_Process = AverageR *LineListNewc[IDnum].linelength;
		LineListNewc[IDnum].Bpu_Process = AverageB *LineListNewc[IDnum].linelength;
		LineListNewc[IDnum].LinePro = "补全电阻、电纳值";//错误修正5：平均值反推长度合理，补全电阻、电纳
		LineListNewc[IDnum].Xpu_Process = 999999;
		LineListNewc[IDnum].linelength_Process = 999999;
		LineListNewc[IDnum].LineWrongPro = 1;
		//LineListCase5.push_back(LineListNewc[IDnum]);
		LineProblemList.push_back(LineListNewc[IDnum]);
	}
	else
	{
		LineListNewc[IDnum].LinePro = "线路长度不合理";//可能错误5：电抗长度存在； 辨识成功，无法修正，界面展示
		LineListNewc[IDnum].Xpu_Process = 999999;
		LineListNewc[IDnum].Rpu_Process = 999999;
		LineListNewc[IDnum].Bpu_Process = 999999;
		LineListNewc[IDnum].linelength_Process = 999999;
		LineListNewc[IDnum].LineWrongPro = 1;
		//LineListCase5.push_back(LineListNewc[IDnum]);
		LineProblemList.push_back(LineListNewc[IDnum]);
	
	}
	Parameterc.clear();
}

void LineParCheck::BadLineparameterCheckCase6(int IDnum)
{
	double MVA_BASEC = inst->GetMVA_BASE();

    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();
	double LengthInterval = Parameterc[6];//线路长度的相对偏差

	double LineX, LineB;
	LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
	LineB = 2 * LineListNewc[IDnum].Bpu*MVA_BASEC / (LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol);
	double LineLengthXB = GetLineLengthXB(LineX, LineB);
	//单值校验电抗
	double AverageX = 0.32;			//给出单位长度平均线路电抗参数值
	double LineLengthX = LineX / AverageX;
	LineListNewc[IDnum].LineLengthXB = LineLengthXB;
	LineListNewc[IDnum].LineLengthRateX = LineLengthX;
	if(fabs(LineLengthXB - LineLengthX) / LineLengthXB < LengthInterval)
	{
		double AverageR = 0.083;
		LineListNewc[IDnum].linelength_Process = LineLengthXB;
		LineListNewc[IDnum].Xpu_Process = 999999;
		LineListNewc[IDnum].Rpu_Process = AverageR *LineListNewc[IDnum].linelength_Process;
		LineListNewc[IDnum].Bpu_Process = 999999;
		LineListNewc[IDnum].LineWrongPro = 1;
		LineListNewc[IDnum].LinePro = "补全电阻和长度值";//错误修正6：电抗、电纳存在；XB、X平均值反推线路长度合理
		//LineListCase6.push_back(LineListNewc[IDnum]);
		LineProblemList.push_back(LineListNewc[IDnum]);
	}
	else
	{

		LineListNewc[IDnum].LinePro = "线路电抗、电纳不合理";//可能错误6：电抗、电纳存在；辨识成功，无法修正，界面展示
		//LineListCase6.push_back(LineListNewc[IDnum]);
		LineListNewc[IDnum].LineWrongPro = 1;
		LineProblemList.push_back(LineListNewc[IDnum]);
	}
	Parameterc.clear();
}

void LineParCheck::BadLineparameterCheckCase7(int IDnum)
{
	double MVA_BASEC = inst->GetMVA_BASE();

    BPA::BPAFilesIO::GetInitConfigFromDb *ReadIni = new BPA::BPAFilesIO::GetInitConfigFromDb(database);
	std::vector <RXrateStdCfg> RXstandardRatec = ReadIni->GetRXstandardRatec();
	vector<double>Parameterc;
	Parameterc = ReadIni->GetParameter();
	double LengthInterval = Parameterc[6];//线路长度的相对偏差
	int RXrateIDnum = 0;
	double RXrate = 0;
	RXrate = 400 * LineListNewc[IDnum].Rpu / LineListNewc[IDnum].Xpu;
	RXrateIDnum = ReturnStandard(RXrate);		//阻抗比不存在时的情况999
	if(RXrateIDnum ==999)
	{
			LineListNewc[IDnum].LinePro = "线路的参数可能存在问题，阻抗比不在标准阻抗比范围之内";
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Bpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase7.push_back(LineListNewc[IDnum]);	
			LineProblemList.push_back(LineListNewc[IDnum]);
	}
	else
	{
		double LineR, LineX, LineB, LineLengthR, LineLengthX;
		LineR = LineListNewc[IDnum].Rpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		LineX = LineListNewc[IDnum].Xpu*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol / MVA_BASEC;
		LineLengthR = LineR / RXstandardRatec[RXrateIDnum].Rstandard;
		LineLengthX = LineX / RXstandardRatec[RXrateIDnum].Xstandard;
		LineListNewc[IDnum].LineLengthRateR = LineLengthR;
		LineListNewc[IDnum].LineLengthRateX = LineLengthX;
		if (fabs(LineLengthR - LineLengthX) / LineLengthX < LengthInterval)
		{
			double LineLengthRX = (LineLengthR + LineLengthX) / 2;
			LineListNewc[IDnum].linelength_Process = LineLengthRX;
			LineB = RXstandardRatec[RXrateIDnum].Bstandard * LineLengthRX;
			LineListNewc[IDnum].Bpu_Process = LineB*LineListNewc[IDnum].StartVol*LineListNewc[IDnum].StartVol /	(2000000*MVA_BASEC);	// 补全电纳值
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].LinePro = "补全电纳、长度值";
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase7.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
		}
		else
		{
			LineListNewc[IDnum].LinePro = "电阻、电抗不合理";		//可能错误7： 电抗、电阻存在；辨识成功，无法修正，界面展示
			LineListNewc[IDnum].Xpu_Process = 999999;
			LineListNewc[IDnum].Rpu_Process = 999999;
			LineListNewc[IDnum].Bpu_Process = 999999;
			LineListNewc[IDnum].linelength_Process = 999999;
			LineListNewc[IDnum].LineWrongPro = 1;
			//LineListCase7.push_back(LineListNewc[IDnum]);
			LineProblemList.push_back(LineListNewc[IDnum]);
		}
	}
	Parameterc.clear();
	RXstandardRatec.clear();
}

void LineParCheck::BadLineparameterCheckCase8(int IDnum)
{
	LineListNewc[IDnum].LinePro = "仅存在线路电抗，无法辨识，不做修正";
	LineListNewc[IDnum].Xpu_Process = 999999;
	LineListNewc[IDnum].Bpu_Process = 999999;
	LineListNewc[IDnum].Rpu_Process = 999999;
	LineListNewc[IDnum].linelength_Process = 999999;
	LineListNewc[IDnum].LineWrongPro = 1;
	//LineListCase8.push_back(LineListNewc[IDnum]);
	LineProblemList.push_back(LineListNewc[IDnum]);
}

void LineParCheck::BadLineparameterCheckCase9(int IDnum)
{
	LineListNewc[IDnum].LinePro = "线路电抗不存在，无法辨识，不做修正";
	LineListNewc[IDnum].Xpu_Process = 999999;
	LineListNewc[IDnum].Bpu_Process = 999999;
	LineListNewc[IDnum].Rpu_Process = 999999;
	LineListNewc[IDnum].linelength_Process = 999999;
	LineListNewc[IDnum].LineWrongPro = 1;
	//LineListCase9.push_back(LineListNewc[IDnum]);
	LineProblemList.push_back(LineListNewc[IDnum]);
}